package hot_100;

public class 搜索二维矩阵 {
    public static void main(String[] args) {

    }

    public boolean searchMatrix(int[][] matrix, int target) {
        int n = matrix.length;
        int m = matrix[0].length;
        for (int i = 0; i < n; i++) {
            if (matrix[i][m - 1] < target)
                continue;
            int l = 0, r = m - 1;
            while (r > l) {
                int mid = (r + l) >> 1;
                if (matrix[i][mid] >= target)
                    r = mid;
                else
                    l = mid + 1;
            }
            if (matrix[i][r] == target)
                return true;
        }
        return false;
    }
}
